<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    //promise.resolve 是成功状态promise的一种简写形式
    //一般参数
    Promise.resolve('foo').then(data=>{console.log(data);})
    //参数 Promise
    const p1=new Promise(resolve=>{
      setTimeout(() => {
        resolve('我执行了')
      }, 1000);
    })
    Promise.resolve(p1).then(data=>{
      console.log(data);
    })
    //等价于
    p1.then(data=>{
      console.log(data);
    })
    console.log(Promise.resolve(p1)===p1);
    //当resolve函数接受的是promise对象时，后面then会根据传递的Promise对象的状态变化决定执行哪一个回调
    new Promise(resolve=>resolve(p1)).then(data=>{console.log(data);})
    //具有then方法的对象
    const thenable={
      then(resolve,reject){
        console.log('then');
        resolve('data')
        // reject('reason')
      }
    }
    Promise.resolve(thenable).then(data=>console.log(data),err=>console.log(err))
    console.log(Promise.resolve(thenable));
    //promise.reject 是失败状态promise的一种简写形式
    //不管什么参数，都会原封不动地向后传递，作为后续方法的参数
    Promise.reject(p1).catch(err=>console.log(err))
    new Promise((resolve,reject)=>{
      resolve(123)
    }).then(data=>{
      // return data
      // return Promise.resolve(data)
      return Promise.reject('reason')
    }).catch(err=>console.log(err))
  </script>
</body>
</html>